package net.bezrabotnih.client.managed.activity;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.inject.Inject;

import net.bezrabotnih.client.scaffold.place.ProxyPlace;
import net.bezrabotnih.client.managed.request.ApplicationRequestFactory;
import net.bezrabotnih.client.managed.request.ApplicationEntityTypesProcessor;
import net.bezrabotnih.client.managed.request.UserRatingProxy;
import net.bezrabotnih.client.managed.activity.UserRatingActivitiesMapper;
import net.bezrabotnih.client.managed.request.UserAccountProxy;
import net.bezrabotnih.client.managed.activity.UserAccountActivitiesMapper;


import net.bezrabotnih.client.managed.request.ThumbnailProxy;
import net.bezrabotnih.client.managed.activity.ThumbnailActivitiesMapper;
import net.bezrabotnih.client.managed.request.PhotoProxy;
import net.bezrabotnih.client.managed.activity.PhotoActivitiesMapper;
import net.bezrabotnih.client.managed.request.LoginActionProxy;
import net.bezrabotnih.client.managed.activity.LoginActionActivitiesMapper;
import net.bezrabotnih.client.managed.request.JobTypeProxy;
import net.bezrabotnih.client.managed.activity.JobTypeActivitiesMapper;
import net.bezrabotnih.client.managed.request.JobProxy;
import net.bezrabotnih.client.managed.activity.JobActivitiesMapper;
import net.bezrabotnih.client.managed.request.CommentProxy;
import net.bezrabotnih.client.managed.activity.CommentActivitiesMapper;

/**
 * Instantiates detail activities.
 */
public class ApplicationDetailsActivities implements ActivityMapper {
  private final ApplicationRequestFactory requests;
  private final PlaceController placeController;

  @Inject
  public ApplicationDetailsActivities(ApplicationRequestFactory requestFactory, PlaceController placeController) {
    this.requests = requestFactory;
    this.placeController = placeController;
  }

  public Activity getActivity(Place place) {
    if (!(place instanceof ProxyPlace)) {
      return null;
    }

    final ProxyPlace proxyPlace = (ProxyPlace) place;

    return new ApplicationEntityTypesProcessor<Activity>() {
      @Override
			public void handleUserRating(UserRatingProxy proxy) {
				setResult(new UserRatingActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handleUserAccount(UserAccountProxy proxy) {
				setResult(new UserAccountActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}

      @Override
			public void handleThumbnail(ThumbnailProxy proxy) {
				setResult(new ThumbnailActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handlePhoto(PhotoProxy proxy) {
				setResult(new PhotoActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handleLoginAction(LoginActionProxy proxy) {
				setResult(new LoginActionActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handleJobType(JobTypeProxy proxy) {
				setResult(new JobTypeActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handleJob(JobProxy proxy) {
				setResult(new JobActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
      @Override
			public void handleComment(CommentProxy proxy) {
				setResult(new CommentActivitiesMapper(requests, placeController).getActivity(proxyPlace));
			}
    }.process(proxyPlace.getProxyClass());
  }
}
